#include<string.h>
#include<iostream.h>

#define MAXOPS 25

class optabtype
{
 public:
    struct
    {
     char mnemonic[7];
     char code[3];
    } op[MAXOPS];

   optabtype(); //Constructor
   int ismnemonic(char t[7]);
   char *codeof(char t[7]);
};

 //Constructor to initialize the OpTable
optabtype::optabtype()
  {
   strcpy(op[ 0].mnemonic , "ADD   "); strcpy(op[ 0].code , "18");
   strcpy(op[ 1].mnemonic , "AND   "); strcpy(op[ 1].code , "40");
   strcpy(op[ 2].mnemonic , "COMP  "); strcpy(op[ 2].code , "28");
   strcpy(op[ 3].mnemonic , "DIV   "); strcpy(op[ 3].code , "24");
   strcpy(op[ 4].mnemonic , "J     "); strcpy(op[ 4].code , "3C");
   strcpy(op[ 5].mnemonic , "JEQ   "); strcpy(op[ 5].code , "30");
   strcpy(op[ 6].mnemonic , "JGT   "); strcpy(op[ 6].code , "34");
   strcpy(op[ 7].mnemonic , "JLT   "); strcpy(op[ 7].code , "38");
   strcpy(op[ 8].mnemonic , "JSUB  "); strcpy(op[ 8].code , "48");
   strcpy(op[ 9].mnemonic , "LDA   "); strcpy(op[ 9].code , "00");
   strcpy(op[10].mnemonic , "LDCH  "); strcpy(op[10].code , "50");
   strcpy(op[11].mnemonic , "LDL   "); strcpy(op[11].code , "08");
   strcpy(op[12].mnemonic , "LDX   "); strcpy(op[12].code , "04");
   strcpy(op[13].mnemonic , "MUL   "); strcpy(op[13].code , "20");
   strcpy(op[14].mnemonic , "OR    "); strcpy(op[14].code , "44");
   strcpy(op[15].mnemonic , "RD    "); strcpy(op[15].code , "D8");
   strcpy(op[16].mnemonic , "RSUB  "); strcpy(op[16].code , "4C");
   strcpy(op[17].mnemonic , "STA   "); strcpy(op[17].code , "0C");
   strcpy(op[18].mnemonic , "STCH  "); strcpy(op[18].code , "54");
   strcpy(op[19].mnemonic , "STL   "); strcpy(op[19].code , "14");
   strcpy(op[20].mnemonic , "STX   "); strcpy(op[20].code , "10");
   strcpy(op[21].mnemonic , "SUB   "); strcpy(op[21].code , "1C");
   strcpy(op[22].mnemonic , "TD    "); strcpy(op[22].code , "E0");
   strcpy(op[23].mnemonic , "TIX   "); strcpy(op[23].code , "2C");
   strcpy(op[24].mnemonic , "WD    "); strcpy(op[24].code , "DC");
  }

int optabtype::ismnemonic(char t[7])
{
   int found=0;
   for(int i=0;i<MAXOPS && !found;i++)
    if(strcmp( op[i].mnemonic, t ) == 0) found=1;
   return(found);
}

char *optabtype::codeof(char t[7])
{
   int found=0;
   for(int i=0;i<MAXOPS && !found;i++)
    if(strcmp( op[i].mnemonic, t ) == 0) return(op[i].code);
   return(NULL);
}